package lumis.portal.localization;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lumis.portal.PortalException;
import lumis.portal.UnexpectedException;
import lumis.portal.controller.ControllerException;
import lumis.portal.controller.ControllerHtml;
import lumis.util.CookieUtil;
import lumis.util.LocaleUtil;

/**
 * Handles localization related requests.
 *
 * @version $Revision: 7370 $ $Date: 2007-06-12 13:50:49 -0300 (Tue, 12 Jun 2007) $
 * @since 4.0.11
 */
public class LocalizationControllerHtml extends ControllerHtml
{
	public LocalizationControllerHtml(HttpServletRequest request, HttpServletResponse response) throws ControllerException, PortalException
	{
		super(request, response);
	}

	public void handleSetLocaleRequest() throws PortalException
	{
		try
		{
			String locale = request.getParameter("lumUserLocale");
			
			if(locale != null)
			{
				Locale curLocale = LocaleUtil.FromString(locale);
				sessionConfig.setLocale(curLocale);
				CookieUtil.setCookie(request, response, "lumUserLocale", curLocale.toString());
			}
	
			response.sendRedirect("../../client/images/Pix.gif");
		}
		catch (PortalException e)
		{
			throw e;
		}
		catch (Exception e)
		{
			throw new UnexpectedException(e);
		}
	}
}
